4 GUI.cocoa; // use CocoaGUI (Mac OS X native)
5 GUI.swing; // use SwingGUI (Java based GUI)
7 ////////////////////////////////////////////////////////////////////////
10 // create a window. set properties from a routine.
11 // note: alpha transparency works on Mac OS X only!
13 w = Window("trem", Rect(512, 256, 360, 130));
18 w.bounds = w.bounds.moveBy(10.rand2, 10.rand2);
19 w.alpha = cos(i*0.1pi)*0.5+0.5;
27 ////////////////////////////////////////////////////////////////////////
30 // create an array of buttons.
33 w = Window("button panel", Rect(128, 64, 340, 360));
34 w.view.decorator = FlowLayout(w.view.bounds);
36 b = Button(w, Rect(0,0, 75, 24));
37 b.states = [["Start "++i, Color.black, Color.rand],["Stop "++i, Color.white, Color.red]];
40 //w.view.background = Color(0.6,0.8,0.8);
44 ////////////////////////////////////////////////////////////////////////
47 // create a GUI window with some NumberBoxes.
48 // You can command click (CocoaGUI) or control click (SwingGUI) on a control
49 // to drag its value to another control
51 w = Window("number box test", Rect(128, 64, 260, 80));
52 w.view.decorator = f = FlowLayout(w.view.bounds);
54 n = NumberBox(w, Rect(0,0,80,24));
57 n = NumberBox(w, Rect(0,0,80,24));
60 n = DragBoth(w, Rect(0,0,80,24));
65 s = Slider(w, Rect(0,0,240,24));
70 ////////////////////////////////////////////////////////////////////////
73 // create a GUI for a mixer.
76 w = Window("mixer", Rect(128, 64, 340, 360));
77 w.view.decorator = f = FlowLayout(w.view.bounds,Point(4,4),Point(4,2));
79 var v, s, n, spec, p, height = 16;
81 v = StaticText(w, Rect(0, 0, 56, height+2));
83 v.font = Font("Helvetica", 13).boldVariant;
84 v.stringColor = Color.yellow;
86 v.font = Font("Helvetica", 12);
87 v.stringColor = Color.white;
90 s = Slider(w, Rect(0, 0, 182, height));
95 db = spec.map(s.value).round(0.1);
96 //v.string = if (db < -100, { "-inf" },{ db.asString ++ " dB" });
97 v.string = db.asString ++ " dB" ;
101 n = StaticText(w, Rect(0, 0, 72, height+2));
104 n.stringColor = Color.yellow;
105 n.font = Font("Helvetica", 13).boldVariant;
107 n.string = "Channel " ++ i;
108 n.stringColor = Color.white;
109 n.font = Font("Helvetica", 12);
111 n.background = Color.rand(0.1,0.5);
116 w.view.background = Color.blue; // fallback on SwingOSC
117 w.view.background = HiliteGradient(Color.blue, Color.green, \h, 128, 0.3);
122 ////////////////////////////////////////////////////////////////////////
125 // jumble of controls
129 a = Slider(w, Rect(20,20,114,24));
131 b = Button(w, Rect(20, 50, 80, 24));
133 b.states = [["Start Sound", Color.red, Color.grey(0.9)],["Stop Sound", Color.white, Color.grey(0.4)]];
135 c = DragSource(w, Rect(120, 50, 80, 24));
136 c.string = "DragSource";
137 c.font = Font("Helvetica", 12);
138 c.beginDragAction = { arg view; [view.object,view.object]; };
139 //c.stringColor = Color(0.5, 0.2, 0.7);
142 d = DragSink(w, Rect(120, 85, 80, 24));
143 d.string = "DragSink";
145 z = CompositeView(w, Rect(0,100,800,300));
147 l = Slider(z, Rect(20,120,180,24));
149 //l.backColor = Color(0,1,0);
150 //l.knobColor = Color(1,0,0);
153 r = RangeSlider(z, Rect(20,170,180,24));
156 q = RangeSlider(z, Rect(220, 170, 24, 180));
158 t = Slider2D(w, Rect(220,20, 80, 80));
159 t.action = { arg slider; c.object = slider.y.postln.round(0.001); };
161 p = Slider(z, Rect(248, 170, 24, 180));
162 p.action = { arg slider; slider.value.postln; };
168 // properties you can set in the window above.
169 w.view.background = Color.blue; // fallback on SwingOSC
170 w.view.background = HiliteGradient(Color.blue, Color.red, \v, 128, 0.2);
171 r.background = Color.gray; r.hi = 0.2;
176 z.enabled = false; // NO EFFECT WITH SWINGOSC!
204 c.object = Point(3,4);
206 c.object = [1, 2, 3, 4];
208 c.object = WhiteNoise.ar(1);
209 c.object = WhiteNoise;
219 ////////////////////////////////////////////////////////////////////////
221 // create a window to start and stop a synth
224 SynthDef("moto-rev", {
226 x = RLPF.ar(LFPulse.ar(SinOsc.kr(0.2, 0, 10, 21), [0,0.1], 0.1), 100, 0.1).clip2(0.4);
232 var w, b1, b2, b3, name, a, s;
235 w = Window(name.asString, Rect(128, 64, 260, 80));
236 w.view.decorator = FlowLayout(w.view.bounds);
238 b1 = Button(w, Rect(0,0, 80, 24));
239 b1.states = [["Load", Color.black, Color.green]];
240 b1.action = { arg view;
241 s.sendMsg("/d_load", SynthDef.synthDefDir ++ name ++ ".scsyndef");
243 b1.enabled = s.serverRunning;
245 b2 = Button(w, Rect(0,0, 80, 24));
247 ["Play", Color.black, Color.green],
248 ["Stop", Color.white, Color.red],
250 b2.action = { arg view;
252 s.sendMsg("/s_new", name, 1001, 1, 0);
254 s.sendMsg("/n_free", 1001);
257 b2.enabled = s.serverRunning;
259 a = SimpleController(s);
261 b1.enabled = server.serverRunning;
262 b2.enabled = server.serverRunning;
264 a.put(\serverRunning, f);
267 s.sendMsg("/n_free", 1001);
275 ////////////////////////////////////////////////////////////////////////
277 // GUI to control a synth
280 SynthDef("trem", { arg freq=800, rate=8, amp=0.1;
282 freq = Lag.kr(freq, 0.3);
283 osc = LFTri.ar(freq, 0, SinOsc.kr( rate + [0,0.1],0,amp).max(0));
286 Server.local.sendMsg("/d_load", SynthDef.synthDefDir ++ "trem.scsyndef");
290 var w, f, d, values, server, id, isOn = false;
293 values = IdentityDictionary.new;
294 server = Server.local;
296 f = { arg name, spec = \lin, guispec;
297 var height = 20, v, s, n;
298 guispec = guispec ? spec;
300 guispec = guispec.asSpec;
302 v = StaticText(w, Rect(0, 0, 72, height));
303 v.font = Font("Helvetica", 12);
304 v.stringColor = Color.black;
307 s = Slider(w, Rect(0, 0, 182, height));
310 var val, guival, step;
311 val = spec.map(s.value);
312 values.put(name, val);
313 if (isOn, { server.sendMsg("/n_set", id, name, val); });
314 guival = guispec.map(s.value);
315 step = pow(10, floor(min(0, guival.abs.log10 - 2)));
316 v.string = guival.round(step).asString ++ guispec.units;
318 s.value = spec.unmap(spec.default);
321 n = StaticText(w, Rect(0, 0, 72, height)); n.string = name;
322 n.stringColor = Color.black;
323 n.font = Font("Helvetica", 12);
326 w.view.decorator.nextLine;
330 w = Window("trem", Rect(512, 64, 360, 130));
331 w.view.decorator = d = FlowLayout(w.view.bounds);
333 b1 = Button(w, Rect(0,0, 80, 24));
334 b1.states = [["Load", Color.black, Color.green]];
335 b1.action = { arg view;
336 server.sendMsg("/d_load", "synthdefs/trem.scsyndef");
338 b1.enabled = server.serverRunning;
340 b2 = Button(w, Rect(0,0, 80, 24));
342 ["Play", Color.black, Color.green],
343 ["Stop", Color.white, Color.red],
345 b2.action = { arg view;
347 if (view.value == 1, {
349 msg = ["/s_new", "trem", 2001, 1, 0];
350 values.keysValuesDo({ arg key, value;
351 msg = msg.addAll([key, value]);
353 server.performList(\sendMsg, msg);
356 server.sendMsg("/n_free", 2001);
359 b2.enabled = server.serverRunning;
362 f.value(\freq, \freq);
363 f.value(\rate, \lofreq);
364 f.value(\amp, \amp, \db);
366 a = SimpleController(server);
368 b1.enabled = server.serverRunning;
369 b2.enabled = server.serverRunning;
370 if (server.serverRunning.not, { b2.value = 0 });
372 a.put(\serverRunning, f);
374 if (isOn, { server.sendMsg("/n_free", 2001) });
381 ////////////////////////////////////////////////////////////////////////
385 // create a GUI window with some SCPopUpMenus.
387 w = Window("popup menu test", Rect(128, 64, 260, 110));
388 w.view.decorator = f = FlowLayout(w.view.bounds);
389 a = ["linear", \exponential, "very long item name", \sine, "welch", "curve -2", "db fader", "squared", "cubed"];
391 n = PopUpMenu(w, Rect(0,0,80,22));
394 n = PopUpMenu(w, Rect(0,0,80,22));
397 n = PopUpMenu(w, Rect(0,0,80,22));
402 n = PopUpMenu(w, Rect(0,0,80,22));
406 n = PopUpMenu(w, Rect(0,0,80,22));
408 n.background = Color.red;
410 n = PopUpMenu(w, Rect(0,0,80,22));
412 n.background = Color.blue;
413 n.stringColor = Color.white;
415 n.action = { arg view; view.value.postln; };
419 s = Slider(w, Rect(0,0,240,24));